package com.example.inventorywarningdemo.until;

import com.example.inventorywarningdemo.service.AlertService;
import com.example.inventorywarningdemo.service.StoreService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 定时检查库存并发送邮件提醒
 */
@Component
@EnableScheduling
@RequiredArgsConstructor
@Slf4j
public class InventoryScheduler {
    private final AlertService alertService;

    @Scheduled(cron = "#{alertConfig.cronExpression}")
    @Async("taskExecutor")
    public void scheduledInventoryCheck() {
        log.info("定时任务触发时间: {}", LocalDateTime.now());
        alertService.checkDailySales();
    }
}